package com.supermap.dataservice.deviceinfo;

import com.supermap.dataservice.deviceinfo.dao.AgriculturalParkDao;
import com.supermap.dataservice.util.JSONUtil;
import com.supermap.dubbo.api.deviceinfo.AgriculturalParkService;
import com.supermap.dubbo.api.deviceinfo.entity.AgriculturalPark;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.dubbo.config.annotation.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author:langhongshuai
 * @Description:农业园逻辑处理层
 * @Date:18/5/19 下午11:21
 */
@Service
public class AgriculturalParkServiceImpl implements AgriculturalParkService {


    /**
     *使用指定类初始化日志对象，在日志输出的时候，可以打印出日志信息所在类
     */
    protected static final Logger logger = LoggerFactory.getLogger(AgriculturalParkServiceImpl.class);



    @Resource
    private AgriculturalParkDao agriculturalParkDao;


    @Override
    public JSONUtil getAllAgriculturalPark() {
        //初始化Json封装工具类
        JSONUtil jsonUtil = new JSONUtil();
        try {
            //获得所有的园区信息
            List<AgriculturalPark> agriculturalParkList = agriculturalParkDao.getAllPark();

            //获得所有的园区信息后返回的json数据
            jsonUtil.setMsg("Get agriculturalParks success！");
            jsonUtil.setIsSuccess(true);
            jsonUtil.setCode(200);
            jsonUtil.setData(agriculturalParkList);
        }catch (Exception e) {
            //捕捉数据库异常
            logger.error("AgriculturalParkServiceImpl=>getAllAgriculturalPark=>DaoException:"+e.getMessage());
            jsonUtil.setMsg("Get agriculturalParks flase！");
            jsonUtil.setIsSuccess(false);
            jsonUtil.setCode(100);
        }
        return jsonUtil;
    }
}
